from pyecharts import options as opts
from pyecharts.charts import Map
from mysql import sqlExecute
import time


#获取全国各省数据疫情数据
def getData():
    sqlDb = sqlExecute.MysqlDb()
    lists = []
    list_area = []
    list_today_confirm = []
    list_total_nowConfirm = []
    list_total_confirm = []
    list_total_suspect = []
    list_total_dead = []
    list_total_heal = []
    # 获取当天时间
    today_time = time.strftime("%Y-%m-%d", time.localtime())
    today_str = today_time + '%'
    sql = "select * from covid_province where lastUpdateTime like '%s'"%today_str
    result = sqlDb.selectAll(sql)
    for i in range(0,len(result)-1):
        list_area.append(result[i][2]) #省份
        list_today_confirm.append(result[i][3])  # 当天确诊数
        list_total_nowConfirm.append(result[i][5])  # 现存确诊
        list_total_confirm.append(result[i][6])  # 总确诊数
        list_total_suspect.append(result[i][7]) # 疑似病例
        list_total_dead.append(result[i][8]) # 死亡病例
        list_total_heal.append(result[i][9])  #治愈病例
    lists.append(list_area)
    lists.append(list_today_confirm)
    lists.append(list_total_nowConfirm)
    lists.append(list_total_confirm)
    lists.append(list_total_suspect)
    lists.append(list_total_dead)
    lists.append(list_total_heal)
    return lists

def showMap():
    result = getData()
    c = (
        Map()
        .add("确诊病例", [list(z) for z in zip(result[0], result[3])], "china")
        .set_global_opts(title_opts=opts.TitleOpts(title="中国各省新冠肺炎确诊分布图",subtitle="数据来源：腾讯疫情数据统计"),
                         visualmap_opts=opts.VisualMapOpts(
                             max_=200,
                             is_piecewise=True,
                             pieces =[{"max":9, "min":0, "label":"0-9", "color":"#FFE4E1"},
                             {"max":99, "min":10, "label":"10-99", "color":"#FF7F50"},
                             {"max":499, "min":100, "label":"100-4999", "color":"#F08080"},
                             {"max":999, "min":500, "label":"500-999", "color":"#CD5C5C"},
                             {"max":9999, "min":1000, "label":"1000-9999", "color":"#990000"},
                             {"max":99999, "min":10000, "label":"10000-99999", "color":"#660000"}, ]
                            ),
                         )
        .render("china.html")
    )


def main():
    getData()
    # showMap()


if __name__ == '__main__':
    main()